using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using B.S.Data.MES.API.Applications.CangKu.Command;

namespace B.S.Data.MES.API.Applications.CangKu.CommandHandlers
{
    public class UpdateCangKuQUCommandHandler : IRequestHandler<UpdateCangKuQUCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<CangKuQU> _cangKuQURepository;
        private readonly IMapper _mapper;

        public UpdateCangKuQUCommandHandler(IBaseRepository<CangKuQU> cangKuQURepository, IMapper mapper)
        {
            _cangKuQURepository = cangKuQURepository;
            _mapper = mapper;
        }

        public async Task<APIRequst<int>> Handle(UpdateCangKuQUCommand request, CancellationToken cancellationToken)
        {

            // 使用AutoMapper更新属性
            var su = _mapper.Map<CangKuQU>(request);
            su.UpdateTime = DateTime.Now;
            su.CreateTime=DateTime.Now;
            var result = await _cangKuQURepository.Update(su);
            
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString(),
            };
        }
    }
}